Page({
  data: {
    latitude: '',
    longitude: '',
    markers: [
      {longitude: "113.838123",latitude: "22.62618"},
      {longitude: "113.836893",latitude: "22.627237"},
    ],
    polyline: [
      {
        color: '#ff0000',
        width: 5,
        dottedLine: true,
        points: [
          {longitude: "113.838123",latitude: "22.62618"},
          {longitude: "113.836893",latitude: "22.627237"}
        ], // 经纬度坐标点集合
      },
      {
        color: '#ff0000',
        width: 5,
        dottedLine: true,
        points: [
          {longitude: "113.838123",latitude: "22.62618"},
          {longitude: "113.841563",latitude: "22.62982"}
        ], // 经纬度坐标点集合
      }
    ]
  },
  onLoad() {
    // 通过 wx.createMapContext('mapId', component) 创建 MapContext
    this.mapCtx = wx.createMapContext('map')
    // console.log('===', this.mapCtx)

    this.initLocation()
  },
  handleTap(e) {
    // 获取点击位置的经纬度
    const {latitude, longitude} = e.detail
    // 1. 通过props的方法来添加 标记点
    // this.setData({
    //   markers: [...this.data.markers, {latitude, longitude}]
    // })
    // 2. 通过mapCtx的方式来添加 标记点
    this.mapCtx.addMarkers({
      markers: [
        {id: 1, latitude, longitude}
      ],
      success() {
        console.log('success')
      },
      fail(res) {
        console.log('===', res)
      }
    })
  },
  initLocation() {
    var that = this
    // 调用 wx.getLocation() 获取用户的地理位置
    wx.getLocation({
      type: 'gcj02',
      success(res) {
        console.log('res', res)
        that.setData({
          latitude: res.latitude,
          longitude: res.longitude
        })
      },
      fail: (res) => {
        console.log('fail', res)
      }
    })
  },
  fn1() {
    // 打开地图选择位置
    // wx.chooseLocation({
    //   success: (res) => {
    //     console.log('success', res)
    //   },
    //   fail: (res) => {
    //     console.log('fail', res)
    //   }
    // })

    wx.choosePoi()
  },

  getUserInfo01() {
    wx.getUserInfo({
      success: (res) => {
        console.log('success', res)
      }
    })
  },

  getUserInfo02(e) {
    console.log('e', e)
  },

  getUserInfo03() {
    wx.getUserProfile({
      desc: 'wo yao huoqu ni de xinxi',
      success: (res) => {
        console.log('res', res)
      }
    })
  },

  fn2(e) {
    console.log('e', e)
  }
})